﻿using System.Collections.Generic;
using Chappie.Infrastructure.DataStructure;
using Chappie.Infrastructure.Domain;
using Chappie.Infrastructure.Specification;

namespace Chappie.Infrastructure.Repository
{
    /// <summary>
    /// 仓储接口
    /// </summary>
    /// <typeparam name="TAggregateRoot">聚合根类型。</typeparam>
    public interface IRepository<TAggregateRoot>
        where TAggregateRoot : class, IAggregateRoot
    {
        #region Func

        /// <summary>
        /// 将指定的聚合根添加到仓储中。
        /// </summary>
        /// <param name="aggregateRoot">需要添加到仓储的聚合根实例。</param>
        void Add(TAggregateRoot aggregateRoot);

        /// <summary>
        /// 将指定的聚合根从仓储中移除。
        /// </summary>
        /// <param name="aggregateRoot">需要从仓储中移除的聚合根。</param>
        void Remove(TAggregateRoot aggregateRoot);

        /// <summary>
        /// 更新指定的聚合根。
        /// </summary>
        /// <param name="aggregateRoot">需要更新的聚合根。</param>
        void Update(TAggregateRoot aggregateRoot);

        /// <summary>
        /// 从仓储中查询符合规约的唯一聚合根
        /// </summary>
        /// <param name="specification">规约</param>
        /// <returns>唯一聚合跟或默认值</returns>
        TAggregateRoot FindSingleOrDefault(ISpecification<TAggregateRoot> specification);

        /// <summary>
        /// 查询符合规约的聚合根是否存在
        /// </summary>
        /// <param name="specification">规约</param>
        /// <returns></returns>
        bool Exists(ISpecification<TAggregateRoot> specification);

        /// <summary>
        /// 从仓储中查找所有聚合根。
        /// </summary>
        /// <returns>所有的聚合根。</returns>
        IEnumerable<TAggregateRoot> FindAll();

        /// <summary>
        /// 从仓储中查找所有聚合根（分页结果）
        /// </summary>
        /// <param name="pageNumber"> </param>
        /// <param name="pageSize"> </param>
        /// <returns></returns>
        PagedResult<TAggregateRoot> FindAll(int pageNumber, int pageSize);

        /// <summary>
        /// 从仓储中查找符合规约的所有聚合根。
        /// </summary>
        /// <param name="specification">规约</param>
        /// <returns>所有的聚合根。</returns>
        IEnumerable<TAggregateRoot> FindAll(ISpecification<TAggregateRoot> specification);

        /// <summary>
        /// 从仓储中查找符合规约的所有聚合根（分页结果）
        /// </summary>
        /// <param name="specification"></param>
        /// <param name="pageNumber"> </param>
        /// <param name="pageSize"> </param>
        /// <returns></returns>
        PagedResult<TAggregateRoot> FindAll(ISpecification<TAggregateRoot> specification, int pageNumber, int pageSize);

        #endregion
    }
}